<?php

namespace ctrl;

use common\Ctrl;
use model\feedbacks;
use libs\view;

class feedback extends ctrl
{
	static function init()
	{
		\model\visits::insertData(); //用户访问记录 写入记数
	}

	public static function index()
	{
		$list = feedbacks::selectData();
		view::assign('list', $list['data']);
		view::assign('page', $list['page']);
		view::display();
	}

	public static function info()
	{
		if (!isset($_GET['id']) & empty($_GET['id']) & empty(ROUTE['params']['id'])) {
			return  parent::_404();
		}

		$info = feedbacks::findData();
		if (empty($info)) {
			return  parent::_404();
		}
		view::assign('info', $info);
		view::Display();
	}

	public static function add()
	{
		view::Display();
	}

	public static function post()
	{
		$checkVer = \libs\verimg::check($_POST['vercode'],'cxuu_feedback');    //cxuu_feedback 为默认值'_verimgcode'时可省略
        if(!$checkVer){
			Response(array('status' => 0, 'info' => '验证码错误'));
        }

		$result = feedbacks::insertData();
		if ($result['status']) {
			Response(array('status' => $result['status'], 'info' => $result['msg']));
		} else {
			Response(array('status' => $result['status'], 'info' => $result['msg']));
		}
	}

	/* 
	*  验证码
	*  $width;         //验证码图片的宽度
	*  $height;        //验证码图片的高度
	*  $codeNum;   //验证码字符的个数
	*  $fontSize;      //字符尺寸
	*/
	public static function vercode()
	{
		$ver = new \libs\verimg(100, 36, 4, 12);
		$ver->Img('cxuu_feedback');  ///将验证码的md5值存入$_SESSION['cxuu_feedback']中，以便后续验证使用；cxuu_feedback可以省略，默认为'_verimgcode'
	}
}
